import java.util.*;

/*
* 这个类用来运用ArrayList的用法
* */
public class ArrayListTest {


    public static  void main(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(5);
        arrayList.add(2);
        arrayList.add(0);
        System.out.println(arrayList);
        //1.
        for (int i = 0; i < arrayList.size(); i++) {
            System.out.print(arrayList.get(i)+" ");
        }
        System.out.println();
        for (int x:arrayList) {
            System.out.print(x+" ");
        }
        System.out.println();
        Iterator<Integer> it = arrayList.iterator();//获取到线性表的迭代器
        //开始遍历
        while(it.hasNext()) {
            System.out.print(it.next()+" ");
        }
        System.out.println();
        ListIterator<Integer> it2 = arrayList.listIterator();
        while(it2.hasNext()) {
            System.out.print(it2.next()+" ");
        }
        System.out.println();
        ListIterator it3 = arrayList.listIterator(arrayList.size());//让迭代器指向最后一个元素后面
        while (it3.hasPrevious()) {
            System.out.print(it3.previous()+" ");//打印前一个
        }


    }
    public static void main8(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(10);
        arrayList.add(20);
        arrayList.add(30);
        arrayList.add(40);
        System.out.println("修改前：");
        System.out.println("arrayList:"+arrayList);

        List<Integer> list = arrayList.subList(1,3);
        System.out.println("list:"+list);

        list.set(0,999);
        list.set(0,888);

        System.out.println("修改后：");
        System.out.println("arrayList:"+arrayList);
        System.out.println("list:"+list);


    }

    public static void main7(String[] args) {
      ArrayList<Integer> arrayList = new ArrayList<>();
      arrayList.add(0,9);
        arrayList.add(0,9);
        arrayList.add(0,7);
        System.out.println(arrayList);
    }

    public static void main6(String[] args) {
        List<Integer> list = new ArrayList<>();
        List<Integer> list2 = new ArrayList<>(list);
        ArrayList<Integer> list3 = new ArrayList<>(list2);
        List<Integer> list4 = new ArrayList<>(list3);
        ArrayList<Number>  list5 = new ArrayList<>(list4);
    }

    public static void main5(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        ArrayList<Integer> arrayList1 = new ArrayList<>(arrayList);//第三种构造方式
        System.out.println(arrayList1);
    }

    public static void main4(String[] args) {
        ArrayList<Integer> arrayList1 = new ArrayList<>();
        arrayList1.add(1);
        arrayList1.add(2);
        System.out.println(arrayList1);
    }
    public static void main3(String[] args) {
        //简单使用ArrayList
       /* ArrayList<Integer> arrayList = new ArrayList<>();
        ArrayList<String> arrayList1 = new ArrayList<>();
*/

        List<Integer> list = new ArrayList<>();
        list.add(1);
        list.add(3);
        list.add(1);
        list.add(4);
        list.add(5);
        list.add(2);
        list.add(0);
        System.out.println(list);
        list.add(1,999);
        list.add(2,888);
        list.add(1,777);
        list.add(1,666);
        System.out.println(list);
    }

    private static ArrayList<Character> func(String str1,String str2) {
        //删除str1中的str2
        ArrayList<Character> arrayList = new ArrayList<>();
        for (int i = 0; i < str1.length(); i++) {
            char ch = str1.charAt(i);
            if(!str2.contains(ch+"")) {
                arrayList.add(ch);
            }
        }
        return arrayList;
    }
    public static void main2(String[] args) {
        ArrayList<String> arrayList = new ArrayList<>();
        String str1 = "welcome to world";
        String str2 = "come";
        ArrayList<Character> arrayList1 = func(str1,str2);
        System.out.println(arrayList1);

    }
    public static void main1(String[] args) {
        ArrayList<Integer> arrayList = new ArrayList<>();
        arrayList.add(1);
        arrayList.add(2);
        arrayList.add(3);
        arrayList.add(4);
        arrayList.add(1,3);
        System.out.println(arrayList);

        ArrayList<Integer> arrayList1 = new ArrayList<>(arrayList);
        arrayList1.add(999);
        arrayList1.add(888);
        arrayList1.add(777);
        System.out.println(arrayList1);

        List<Integer> list = new ArrayList<>(arrayList1);//提升

    }

}
